home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / tpsc16 / src / differ.c next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  2.8 KB  |  125 lines

  1. /*
  2.     境界抽出ユ-ティリティプログラム
  3.      境界線を微分により計算し2値デ-タに分離する。
  4.     
  5.     [TPSC16]用外部シェルプログラム
  6.     
  7.     Cre.      1993. 3.20  by Yahara
  8.     Rev.1.0   1993. 3.20  by Yahara
  9. */
  10.  
  11. #define EGBSIZE        1536    // EGB用ワ-クサイズ
  12. #define MOSSIZE        4096    // マウス用ワ-クサイズ
  13. #define BOOL        int        // 論理判断の型宣言
  14. #define TRUE        1        // 真
  15. #define FALSE        0        // 偽
  16. #define MENUPAGE    0        // メニュ-ペ-ジ番号
  17. #define DRAWPAGE    1        // 描画ペ-ジ番号
  18. #define SCREEN        3        // 画面モ-ド
  19. #define DRAWWIDE    640        // 処理画面横サイズ
  20. #define DRAWHIDE    480        // 処理画面縦サイズ
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <malloc.h>
  27. #include <math.h>
  28. #include <egb.h>
  29. #include <mos.h>
  30. #include <loader.h>            // コプロセス定義ファイル
  31.  
  32. char EGB_work[EGBSIZE];        // EGBワ-クエリア
  33. char MOS_work[MOSSIZE];        // マウスワ-クエリア
  34.  
  35. char matrix[4][DRAWWIDE];
  36.  
  37. void MatrixInit()
  38. {
  39.     int i,j;
  40.     int col;
  41.     /* 初めの3ライン分のカラ-濃度をマトリックスをセットする */
  42.     for(j=0;j<3;j++) {
  43.         for(i=0;i<DRAWWIDE;i++) {
  44.             EGB_point(EGB_work,0,i,j,&col);
  45.             matrix[j][i] = col;
  46.         }
  47.     }
  48. }
  49.  
  50. void NextMatrixSet(int y)
  51. {
  52.     int i;
  53.     int col;
  54.     /* スキャンするラインの2ライン後をカラ-濃度をセットする */
  55.     for(i=0;i<DRAWWIDE;i++) {
  56.         EGB_point(EGB_work,0,i,y+2,&col);
  57.         matrix[3][i] = col;
  58.     }
  59. }
  60.  
  61. void Pset(int x,int y)
  62. {
  63.     struct {     unsigned short int n;
  64.                 short int x,y; } par;
  65.     /* EGBル-チンの呼び出し */
  66.     par.n = 1;
  67.     par.x = x; par.y = y;
  68.     EGB_pset(EGB_work,(char *)&par);
  69. }
  70.  
  71. void Differental(int x,int y)
  72. {
  73.     int h,v,p;
  74.     
  75.     h = abs(matrix[0][x+1]+matrix[1][x+1]+matrix[2][x+1]
  76.             -matrix[0][x-1]-matrix[1][x-1]-matrix[2][x-1]);
  77.     v = abs(matrix[2][x+1]+matrix[2][x+1]+matrix[2][x+1]
  78.             -matrix[0][x-1]-matrix[0][x-1]-matrix[0][x-1]);
  79.     p = h + v;
  80.     if( p > 0x0f ) p = 0x0f;
  81.     EGB_color(EGB_work,0,p);            // ドットの色を指定
  82.     Pset(x,y);
  83. }
  84.  
  85. void MatrixShift()
  86. {
  87.     /* マトリックバッファをシフトする */
  88.     memmove(&matrix[0][0],&matrix[1][0],DRAWWIDE*3);
  89. }
  90.  
  91. main()
  92. {
  93.     ADDRESS temp;
  94.     int x,y;
  95.     int ch,mx,my;
  96.     
  97.     /* 画面・マウスの初期化 */
  98.     EGB_resolution(EGB_work,MENUPAGE,SCREEN|0x40);        // Page0 Init
  99.     EGB_resolution(EGB_work,DRAWPAGE,SCREEN|0x40);        // Page1 Init
  100.     EGB_displayPage(EGB_work,0,3);                        // 2page view
  101.     MOS_start(MOS_work,MOSSIZE);                        // マウス初期化
  102.     MOS_resolution(MENUPAGE,SCREEN);
  103.     MOS_resolution(DRAWPAGE,SCREEN);
  104.     
  105.     EGB_writePage(EGB_work,DRAWPAGE);    // 描画ペ-ジを指定
  106.     EGB_paintMode(EGB_work,0x22);        // ペイントモ-ドを指定
  107.     
  108.     /* 処理開始 */
  109.     MatrixInit();
  110.     for(y=1;y<DRAWHIDE-1;y++) {
  111.         MOS_rdpos(&ch,&mx,&my);
  112.         if( ch != 0 ) break;        // マウスが押されたら処理を中断
  113.         NextMatrixSet(y);
  114.         for(x=1;x<DRAWWIDE-1;x++)
  115.             Differental(x,y);
  116.         MatrixShift();
  117.     }
  118.     
  119.     /* 子プロセスの終了処理 */
  120.     MOS_end();
  121.     pcl_get_dta(&temp);
  122.     pcl_exit(0);
  123.     return (0);
  124. }
  125.